<template>
	<view class="content">
		<web-view :webview-styles="webviewStyles"  :src="url"></web-view>
	</view>
</template>

<script>
	
	 
	export default {
		data() {
			return {
				webviewStyles: {
				                    // progress: {
				                    //     color: '#FF3333'
				                    // }
				                },
				currentWebview:null,
				url:''
			}
		},
		onShow() {
			this.init()
		},
		onLoad(options) {
			this.token = uni.getStorageSync("userInfo").token;
			let url = options.url;
			
			for(let key in options){
				if(key != "url"){
					url += "&"+key.replace("amp;","")+"="+options[key]
				}
			}
			
			if(url==1){
				url = uni.getStorageSync("browse_url");
				uni.removeStorageSync("browse_url");
			}
			if(url.indexOf("token")==-1){
			  if(url.indexOf("?")==-1){
				  url = url + "?token="+this.token;
			  }else{
				   url = url + "&token="+this.token;
			  }	
			}
			this.url = url;
			if(options.title){
				this.title=options.title; 
			}
		},
		onReady() {
			if(this.title){
			  uni.setNavigationBarTitle({
			  	title:this.title
			  })	
			}else{
			 uni.autoBackButton=false;
			}
			
			//获取webview页面
			var wv =  this.$scope.$getAppWebview().children()[0];
			wv.addEventListener('loading',()=>{
				uni.showLoading({
					title:"加载中"
				})
			},false)
			wv.addEventListener('loaded',()=>{
				uni.hideLoading();
			},false)
			
		},
		methods: { 
			signal(runType){
				   var currentWebview = this.$scope.$getAppWebview()
				   var wv = currentWebview.children()[0]
				   wv.evalJS("saasApi.signal('"+runType+"')");
			},
			init(){
				let main = plus.android.runtimeMainActivity();
					//为了防止快速点按返回键导致程序退出重写quit方法改为隐藏至后台  
					plus.runtime.quit = ()=>{  
					//main.moveTaskToBack(false);//隐藏页面
					this.signal("页面后退");
					return false;
				};  
				//重写toast方法如果内容为 ‘再按一次退出应用’ 就隐藏应用，其他正常toast  
				plus.nativeUI.toast = ((str)=>{  
					if(str == '再按一次退出应用'){  
						//main.moveTaskToBack(false);//隐藏页面
						this.signal("页面后退");
						return false;  
					}else{  
						uni.showToast({  
							title:str,  
							icon:'none',  
						})
						return false; 
					}
				});
				 
					
				
			}
		},
		onBackPress() {
			//console.log("我返回了");
		},
		
	}
</script>

<stye>

</style>
